//系统必须接口
import axios from '@/api/service.js';
import powerJob from '@/api/powerJob.js';
import api from '@/pub/unit_api.js';
//api 统一控制api前缀
var base_url = api.api.taskJob;
const job = api.api.powerJob;
export default {
      //定时任务查询
      queryJobInfo: (params) => {
        return axios.post(base_url + '/jobInfo/queryJobInfo', params);
      },
      //任务首页报表状态
      chartInfo: (params) => {
        return axios.post(base_url + '/job/chartInfo', params);
      },
      
      // 任务组查询
      queryJobGroupInfo:(params)=>{
        return axios.post(base_url + '/jobGroup/queryJobGroupInfo', params);
      },
      // 日志查询
      queryJobLog:(params)=>{
        return axios.post(base_url + '/jobLog/queryJobLog', params);
      },

      //手动执行一次
      trigger:(params)=>{
        return axios.post(base_url + '/jobInfo/trigger', params);
      },

      /** 任务编辑 */
      editJobInfo:(params)=>{
        return axios.post(base_url + '/jobInfo/editJobInfo', params);
      },
      /** 任务启动 */
      start:(params)=>{
        return axios.post(base_url + '/jobInfo/start', params);
      },
       /** 任务删除 */
      remove:(params)=>{
        return axios.post(base_url + '/jobInfo/remove', params);
      },
      /** 任务暂停 */
      stop:(params)=>{
        return axios.post(base_url + '/jobInfo/stop', params);
      },

      /** powerJob 登录 */
      login:(params)=>{
        return powerJob.post(job + '/auth/thirdPartyLoginDirect', params);
      },
      /** powerJob 注册 */
      register:async (params)=>{
        return await powerJob.post(job + '/pwjbUser/create', params);
      },
      /** powerJob 应用管理主查询 */
      queryAppList:(params)=>{
        return powerJob.post(job + '/appInfo/list', params);
      },
      /** powerJob 命名空间主查询 */
      querySpaceList:(params)=>{
        return powerJob.post(job + '/namespace/list', params);
      },

      /** powerJob 命名空间主查询 */
      queryUserDetail:()=>{
        return powerJob.get(job + '/user/detail');
      },
      /** 修改权限 */
      userModify:(params)=>{
        return powerJob.post(job + '/user/modify', params);
      },
      /** 修改密码 */
      userModifyPwd:(params)=>{
        return powerJob.post(job + '/pwjbUser/changePassword', params);
      },
      /** 修改管理员 */
      modifyManager:(params)=>{
        return powerJob.post(job + '/appInfo/becomeAdmin', params);
      },
      /** 用户列表查询 */
      userQueryList:(params)=>{
        return powerJob.post(job + '/user/query', params);
      },
      /** 服务器信息 */
      getOverview:(params)=>{
        return powerJob.get(job + '/system/overview?appId='+params);
      },
      /** 服务器信息 */
      listWorker:(params)=>{
        return powerJob.get(job + '/system/listWorker?appId='+params );
      },
      /** 任务列表 */
      jobTaskList:(params)=>{
        return powerJob.post(job + '/job/list', params);
      },
      /** 任务保存 */
      saveJob:(params)=>{
        return powerJob.post(job + '/job/save', params);
      },
      /** 任务实例列表 */
      jobTaskInstanceList:(params)=>{
        return powerJob.post(job + '/instance/list', params);
      },
      /** 任务实例详情 */
      jobTaskInstanceDetail:(params)=>{
        return powerJob.post(job + '/instance/detailPlus', params);
      },
      /** 任务实例日志 */
      jobTaskInstanceLog:(params)=>{
        let str = "instanceId="+params.instanceId+"&index="+params.index+"&appId="+params.appId+""
        return powerJob.get(job + '/instance/log?'+str);
      },
      /** 任务运行 */
      runJobTask:(params)=>{
        if(params.instanceParams){
          return powerJob.get(job + '/job/run?jobId='+params.jobId+"&appId="+params.appId+"&instanceParams="+params.instanceParams);
        }else{
          return powerJob.get(job + '/job/run?jobId='+params.jobId+"&appId="+params.appId);
        }
      },
      /** 导出参数 */
      export:(params)=>{
        return powerJob.get(job + '/job/export?jobId='+params.jobId);
      },
      /** 复制 */
      copy:(params)=>{
        return powerJob.post(job + '/job/copy?jobId='+params.jobId);
      },
      /** 删除 */
      deleteJob:(params)=>{
        return powerJob.get(job + '/job/delete?jobId='+params.jobId);
      },
      /** 重试 */
      jobRetry:(params)=>{
        return powerJob.get(job + '/instance/retry?appId='+params.appId+"&instanceId="+params.instanceId); 
      },
      /** 实例停止 */
      jobStop:(params)=>{
        return powerJob.get(job + '/instance/stop?appId='+params.appId+"&instanceId="+params.instanceId);
      }
}